package com.sc.server.system.batch.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 案例参考文档
 * https://www.jianshu.com/p/305192ea4cb1
 */
@RestController
@RequestMapping("batch")
@Api(description = " batch")
public class BatchStartController {
    @Autowired
    JobLauncher jobLauncher;

    @Autowired
    Job processStrJob;
    @Autowired
    Job processMqJob;
    @GetMapping("strStart")
    @ApiOperation("字符串批处理任务调度")
    public void strStart() throws  Exception{
        JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis())
                .toJobParameters();
        jobLauncher.run(processStrJob,jobParameters);
    }
    @GetMapping("mqStart")
    @ApiOperation("字符串批处理任务调度")
    public void mqStart() throws  Exception{
        JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis())
                .toJobParameters();
        jobLauncher.run(processMqJob,jobParameters);
    }
}
